import java.util.ArrayList;


public class partialAssociationElement {
	private String g;
	private String p;
	private String c;   // common child of g and p
	
	private Double g_p;
	private Double g_c;
	private Double p_c;
	
	
	public static Double threshold = 0.0;
	
	public static void setThreshold(Double t)
	{
		threshold = t;
	}
	
	 public partialAssociationElement(String g, String p, String c) {
		  this.g = g;
		  this.p = p;
		  this.c = c;
	 }
	
	 
	 public void set_Rsquare(Float gp, Float gc, Float pc)
	 {
		 g_p = java.lang.Math.sqrt(gp);
		 g_c = java.lang.Math.sqrt(gc);
		 p_c = java.lang.Math.sqrt(pc);
	 }
	 
	 
	 public ArrayList<String> calculatePartialAssociation()
	 {
		 // Find r2 for g-p, g-c and p-c
		 // and return only the ones above threshold
		ArrayList<String> al = new ArrayList<String>();
		
		 Double gp_c = (g_p - (g_c*p_c)) / java.lang.Math.sqrt((1-(g_c*g_c))* (1-(p_c*p_c)));
		 Double gc_p = (g_c - (g_p*p_c)) / java.lang.Math.sqrt((1-(g_p*g_p))* (1-(p_c*p_c)));
		 Double pc_g = (p_c - (g_p*g_c)) / java.lang.Math.sqrt((1-(g_p*g_p))* (1-(g_c*g_c)));
		 
		 // This list returns links to be removed....
		 if(gp_c <= threshold) al.add(g+"-"+p);
		 if(gc_p <= threshold) al.add(g+"-"+c);
		 if(pc_g <= threshold) al.add(p+"-"+c);
		 
		 return al;
	 }
	 
	 public String toString()
	 {
		return g+"-"+p+"-"+c; 
	 }
	  
}
